package asteroids.model.programs.expressions.ComposedExpressions.BinaryExpressions;

import asteroids.model.programs.expressions.BasicExpression;
import asteroids.model.programs.expressions.Expression;
import asteroids.model.programs.expressions.BasicExpressions.DoubleLiteral;
import asteroids.model.programs.expressions.ComposedExpressions.BinaryExpression;
import asteroids.model.programs.types.Type;

public class Division extends BinaryExpression {
	
	/**
	 * Initialize the Divisionn object
	 * 
	 * @param leftExp
	 * 			The left operand of this expression
	 * @param rightExp
	 * 			The right operand of this expression
	 * @effect ...
	 * 			|super(leftExp, rigthExp)
	 */
	public Division(Expression leftExp, Expression rightExp, int line, int column){
		super(leftExp, rightExp, line, column);
	}
	
	/**
	 * Returns the symbol for this Expression, namely /
	 * 
	 * @return ...
	 * 			| return "/"
	 */
	@Override
	public String getOperatorSymbol() {
		return "/";
	}

	/**
	 * Returns the BasicExpression of type DoubleLiteral with the value of the division
	 * 
	 * @return ...
	 * 			| result.equals(new DoubleLiteral(getLeftOperand().getResult().getValue()/
	 * 												getRightOperand().getResult.getValue())
	 */
	@Override
	public BasicExpression getResult() {
		double leftValue = ((DoubleLiteral)getLeftOperand().getResult()).getValue();
		double rightValue = ((DoubleLiteral)getRightOperand().getResult()).getValue();
		double resultValue = leftValue / rightValue;
		BasicExpression result = new DoubleLiteral(resultValue, getLine(), getColumn());
		return result;
	}
	
	@Override
	public Type getType(){
		return Type.DOUBLE;
	}
	
	public Type[] getOperandType(){
		return new Type[]{Type.DOUBLE};
	}
}
